package cn.youyeku.zsxh.ui.teacher;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;

import cn.youyeku.zsxh.R;
import cn.youyeku.zsxh.Utils.AppConfig;
import cn.youyeku.zsxh.common.Contanst;
import cn.youyeku.zsxh.common.DoubleClickExitHelper;
import cn.youyeku.zsxh.ui.UIControl;
import cn.youyeku.zsxh.ui.activity.ABS.BaseActivity;

import static cn.youyeku.zsxh.ui.home.LoginActivity.isLoging;


/**
 * Created by youye on 17-4-14.
 */

public class ActTeacher extends BaseActivity implements View.OnClickListener {
    /**
     * 个人中心
     */
    private Button mTeacherPersonCenter;
    /**
     * 消息中心
     */
    private Button mTeacherMessage;
    /**
     * 发布试题
     */
    private Button mTeacherPostQuestion;
    /**
     * 查看数据统计
     */
    private Button mTeacherGraphicData;
    /**
     * 查看发布的试题
     */
    private Button mTeacherViewSelfData;
    /**
     * 未来功能预留
     */
    private Button future;

    private DoubleClickExitHelper mDoubleClickExitHelper;
    private Context mContext;

    private static final int REQUEST_PERMISSION = 9999;
    //检查权限
    @Override
    public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == REQUEST_PERMISSION) {
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // Permission granted.
            } else {
                // User refused to grant permission.
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.teacher_main);


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
                && ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.CAMERA}, REQUEST_PERMISSION);


        }
        initView();
        mDoubleClickExitHelper = new DoubleClickExitHelper();
        mContext =getApplicationContext();

    }



    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return mDoubleClickExitHelper.onKeyDown(keyCode, event);
    }

    private void initView() {
        mTeacherPersonCenter = (Button) findViewById(R.id.teacher_person_center);
        mTeacherPersonCenter.setOnClickListener(this);
        mTeacherMessage = (Button) findViewById(R.id.teacher_message);
        mTeacherMessage.setOnClickListener(this);
        mTeacherPostQuestion = (Button) findViewById(R.id.teacher_post_question);
        mTeacherPostQuestion.setOnClickListener(this);
        mTeacherGraphicData = (Button) findViewById(R.id.teacher_graphic_data);
        mTeacherGraphicData.setOnClickListener(this);
        mTeacherViewSelfData = (Button) findViewById(R.id.teacher_question_update);
        mTeacherViewSelfData.setOnClickListener(this);
        future = (Button) findViewById(R.id.teacher_setting);
        future.setOnClickListener(this);

    }

    @Override
    public void onBackPressed() {
     
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.teacher_person_center:
                UIControl.showUserInfo(mContext, AppConfig.CONF_USER_ID);
                break;
            case R.id.teacher_message:
                UIControl.showMsgListActivity(mContext);
                break;
            case R.id.teacher_post_question:
                UIControl.showQuestionPostActivity(mContext);
                break;
            case R.id.teacher_graphic_data:
                Contanst.IS_COUNT =true;
                UIControl.showQuestionTeacherList(mContext);
                break;
            case R.id.teacher_question_update:
                Contanst.IS_COUNT =false;
                UIControl.showQuestionTeacherList(mContext);
                break;
            case R.id.teacher_setting:
                UIControl.showSetting(mContext);
                break;
        }
    }
}
